package cn.learn.service.company.impl;

import cn.learn.dao.company.CompanyDao;
import cn.learn.domain.company.Company;
import cn.learn.service.company.CompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired /*ioc中基于动态接口生成的对象*/
    private CompanyDao companyDao;

    /**
     * 查询全部
     * @return
     */
    public List<Company> selectAll() {
        List<Company> selectAll = companyDao.selectAll();
        return selectAll;
    }

    /**
     * 分页查询所有
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo selectAllByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        //2 紧跟的查询方法自动分页
        List<Company> list = companyDao.selectAll();
        //3 封装数据到pageBean(pageInfo)
        PageInfo pb = new PageInfo(list);
        //4 返回pageInfo
        return pb;
    }

    /**
     * 添加一条
     * @param company
     */
    @Override
    public void addOne(Company company) {
        companyDao.addOne(company);
    }

    /**
     * 根据ID查询一条
     * @param company
     * @return
     */
    @Override
    public Company findOneById(Company company) {
        Company resultCompany = companyDao.findOneById(company);
        return resultCompany;
    }

    /**
     * 根据id修改一条数据
     * @param company
     */
    @Override
    public void updateOneById(Company company) {
        companyDao.updateOneById(company);
    }

    /**
     * 根据ID删除一条数据
     * @param id
     */
    @Override
    public void deleteById(String id) {
        companyDao.deleteById(id);
    }


}
